﻿<?php

/**
 * User: yangcheng
 */
header ( "sys_content-type:text/html;charset=utf-8" );  //统一输出编码为utf-8  
$mysql_server_name = "qdm113416174.my3w.com"; //mysql数据库服务器
$mysql_username = "qdm113416174"; //mysql数据库用户名
$mysql_password = "yang147258369"; //mysql数据库密码
$mysql_database = "qdm113416174_db"; //mysql数据【库】名
$mysql_table = "carts"; //mysql数据【表】名


/**
 * 打印函数
 */
function println($msg)
{
    echo json_encode($msg);
}

/** 新建 连接 */
$mysqli = new mysqli($mysql_server_name, $mysql_username, $mysql_password);
/** 调试连接是否正常 */
//var_dump($mysqli);

/** 
 * check connection 
 */
if ($mysqli->connect_errno) {
	$code = 400;
	$msg = "Connect failed: ". $mysqli->connect_error;
	$responce->code = $code; //代码 
	$responce->msg = $msg; //信息
    println($responce);
    exit();
}else{
	$mysqli->set_charset("utf8");//设置读、写数据的编码
	save();
}


function save(){
	global $mysqli,$mysql_database,$mysql_table;
	$mysqli->select_db($mysql_database);

	
	$data=file_get_contents("php://input"); //取得json数据
	$arr = json_decode($data, true);   //格式化

	$pid=intval($arr['pid']);
	$sys_content = $arr['sys_content']; //内容 
	$idcard = strtoupper(preg_replace('# #','',$arr['idcard'])); //车牌号
	$time = date('Y-m-d h:i:s');//创建时间
	 
	//执行SQL 
	$result = $mysqli->query("
		UPDATE  $mysql_table 
		SET idcard='$idcard',sys_content='$sys_content',last_modify_time= '$time'
		WHERE  pid=$pid
	");
	//返回信息
	$code = 0;
	$msg = "修改成功！";
	//是否插入成功判断
	if ($result != true) {
		$code=400;
		$msg =  "修改失败！" ;
	}

	$responce->code = $code; //代码 
	$responce->msg = $msg; //信息
	println($responce); //输出JSON数据 

}

/**
 * 关闭连接
 */
$mysqli->close();

